package com.atguigu.demo.tree;

import javax.swing.*;
import java.awt.*;

public class GraphTree    extends JFrame {
//        private final int W =40; //圆形的宽
//        private final int H =40; //圆形的高
    private final int R =40; //圆形的半径
        private final int width=800;
        private final int height=800;
    public GraphTree(HeroTree root){
            //调用初始化方法
            initialize(root);

        }

        //初始化方法
        private void initialize(HeroTree root) {
            setSize(width,height);     //设置窗体大小
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    //设置窗体关闭模式
            setContentPane(new GraphTree.DrawPanel(root));    //设置窗体面板为绘图面板对象
            setTitle("绘图实例2");          //设置窗体标题
        }

        //创建绘制面板
        class DrawPanel extends JPanel{
        public HeroTree root;
        int x=360;
        int y=10;
        int p=150;//步长
        int c=20; //半径
        int l=15;
        int x1=x+c;
        int y1=y+c;
            int xl=x+l;
            int yl=y+l;
        // 横向移动左减 右加
        // 纵向移动下加 上减
            //重写绘制方法
        public void paint(Graphics g){
            //System.out.println("kaishi");
            int x=360;
            int y=10;
            this.root.preOrder(g, 360,10);
            //圆形
           // g.drawOval(x,y,R,R);

            //直线
           // g.drawLine(x1,y1,x1-p,y1+p);//// 往左下线：X原有位置开始走，到达位置为X-40;Y在原有位置先加20到达位置加40

           // g.drawString("22",xl,yl);//画字符串


        }
            public void paint1(Graphics g){
                System.out.println("kaishi");
              //  this.root.preOrder(g);
                //圆形
                g.drawOval(x,y,R,R);
                g.drawOval(x-p,y+p,R,R);//往左下：X一次减去60，Y一次加60
                g.drawOval(x+p,y+p,R,R);// 往右下：X一次加去60，Y一次加60
                g.drawOval(x-p-p,y+p+p,R,R);
                g.drawOval(x-p+p,y+p+p,R,R);
                //直线
                g.drawLine(x1,y1,x1-p,y1+p);// 往左下线：X原有位置开始走，到达位置为X-40;Y在原有位置先加20到达位置加40
                g.drawLine(x1,y1,x1+p,y1+p);
                g.drawLine(x1-p,y1+p, x1+p-p,y1+p+p);
                g.drawLine(x1-p,y1+p, x1-p-p,y1+p+p);
                g.drawString("22",xl,yl);//画字符串
                g.drawString("22",xl-p,yl+p);//画字符串
                g.drawString("22",xl+p,yl+p);//画字符串
                g.drawString("22",xl-p-p,yl+p+p);//画字符串
                g.drawString("22",xl+p-p,yl+p+p);//画字符串

            }
            public DrawPanel(HeroTree root){
                  this.root=root;
            }


        }

        public static void main(String[] args) {
           new GraphTree(null).setVisible(true);
        }
}
